﻿
////自定义新增方法
var fnCustomAdd = function () {
    var dutyTypeId = document.getElementById("DutyTypeId").value;
    if (dutyTypeId == "" || dutyTypeId == null) {
        alert("请选择左侧职务类型后新增!");
        return;
    } else {
        var pagetitle = document.getElementById("DutyTypeName").value;
        document.getElementById("EditUIWindow").src = "../../EditWidows/OrganizationalManager/AddDutyInfo.aspx?type=0&r=" + Math.random() + "&entity=DatDutyInfo&id=" + dutyTypeId + "&title=" + encodeURI(pagetitle) + "";
        YAHOO.example.container.dialog1.show();
        document.getElementById("yui-gen31-button").style.display = "block";
    }
}
//自定义修改方法
var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    var record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录!");
        return;
    } else {
        var vid = record.getData(const_entityID);
        if (vid != "") {
            var pagetitle = "职务管理";
            document.getElementById("EditUIWindow").src = "/Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=DatDutyInfo&id=" + vid + "&title=" + encodeURI(pagetitle) + "";
            YAHOO.example.container.dialog1.show();
            document.getElementById("yui-gen31-button").style.display = "block";
        }
    }
}

//自动义双击方法
function CustomDbClick() {
    var recordID = myDataTable.getSelectedRows()[0];
    var record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录!");
        return;
    } else {
        var vid = record.getData(const_entityID);
        if (vid != "") {
            var pagetitle = "职务管理";
            document.getElementById("EditUIWindow").src = "../../EditWidows/OrganizationalManager/AddDutyInfo.aspx?type=1&flag=0&r=" + Math.random() + "&entity=DatDutyInfo&id=" + vid + "&title=" + encodeURI(pagetitle) + "";
            YAHOO.example.container.dialog1.show();
            document.getElementById("yui-gen31-button").style.display = "none";
        }
    }
}

//职务类型
var fnDutyInfoType = function () {
    var pagetitle = "职务类型设置";
    //parent.parent.addTabs(pagetitle, '../TR/SubjectList.aspx?r=' + Math.random() + '&entity=V_DatDutyType&title=' + encodeURI(pagetitle) + '');
    //parent.parent.NeedRefreshPage = this;

    //document.getElementById("EditUIWindow").src = "../TR/SubjectList.aspx?r=" + Math.random() + "&entity=V_DatDutyType&title=" + encodeURI(pagetitle) + "";
    //SetMaxDWH(YAHOO.example.container.dialog1);
    //YAHOO.example.container.dialog1.show();
    //document.getElementById("yui-gen7-button").style.display = "none";

    document.getElementById("EditUIWindow").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_DatDutyType&title=" + encodeURI(pagetitle) + "";
    YAHOO.example.container.dialog1.show();
    document.getElementById("yui-gen31-button").style.display = "none";
}
//职等设置
var fnDutyLevelSetting = function () {
    var pagetitle = "职等设置";
    //parent.parent.addTabs(pagetitle, '../TR/SubjectList.aspx?r=' + Math.random() + '&entity=V_DatDutyLevel&title=' + encodeURI(pagetitle) + '');
    //parent.parent.NeedRefreshPage = this;

    //document.getElementById("EditUIWindow").src = "../TR/SubjectList.aspx?r=" + Math.random() + "&entity=V_DatDutyLevel&title=" + encodeURI(pagetitle) + "";
    //SetMaxDWH(YAHOO.example.container.dialog1);
    //YAHOO.example.container.dialog1.show();
    //document.getElementById("yui-gen7-button").style.display = "none";

    document.getElementById("EditUIWindow").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_DatDutyLevel&title=" + encodeURI(pagetitle) + "";
    YAHOO.example.container.dialog1.show();
    document.getElementById("yui-gen31-button").style.display = "none";
}
//职级设置
var fnDutyGrade = function () {
    var pagetitle = "职级设置";
    document.getElementById("EditUIWindow").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_DatDutyGrade&title=" + encodeURI(pagetitle) + "";
    YAHOO.example.container.dialog1.show();
    document.getElementById("yui-gen31-button").style.display = "none";
    
    /*var recordID = myDataTable.getSelectedRows()[0];
    var record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录!");
        return;
    } else {
        var vid = record.getData(const_entityID);
        if (vid != "") {
            var pagetitle = "职级设置";
            //parent.parent.addTabs(pagetitle, '../TR/SubjectList.aspx?r=' + Math.random() + '&entity=V_DatDutyGrade&id=' + vid + '&title=' + encodeURI(pagetitle) + '');
            //parent.parent.NeedRefreshPage = this;

            //document.getElementById("EditUIWindow").src = "../TR/SubjectList.aspx?r=" + Math.random() + "&entity=V_DatDutyGrade&id=" + vid + "&title=" + encodeURI(pagetitle) + "";
            //SetMaxDWH(YAHOO.example.container.dialog1);
            //YAHOO.example.container.dialog1.show();
            //document.getElementById("yui-gen7-button").style.display = "none";

            document.getElementById("EditUIWindow").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_DatDutyGrade&id=" + vid + "&title=" + encodeURI(pagetitle) + "";
            YAHOO.example.container.dialog1.show();
            document.getElementById("yui-gen29-button").style.display = "none";
        }
    }*/
}

//职务对应职级
var fnDutyToGrade = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    var record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录!");
        return;
    } else {
        var vid = record.getData(const_entityID);
        if (vid != "") {
            var pagetitle = "职务对应职级";
            document.getElementById("EditUIWindow").src = "../../EditWidows/OrganizationalManager/AddDutyGrade.aspx?&r=" + Math.random() + "&entity=DatPostDutygrade&id=" + vid + "&title=" + encodeURI(pagetitle) + "";
            YAHOO.example.container.dialog1.show();
            document.getElementById("yui-gen31-button").style.display = "block";
        } 
    }
}

//保存核心人才库页面的职务选择
var fnSaveDatDutyInfo = function () {
    //debugger
    var _PageTitle = parent._employeeTitle;
    var CategoryID = getPar1("CategoryID");
    //alert("CategoryID:" + CategoryID + " _PageTitle:" + _PageTitle);
    var list = this.mDataTable.getRecordSet()._records;
    var elist = [];
    dl = [];
    for (var i = 0; i < list.length; i++) {
        //this.getRecordSet()._records[0]._oData["BarItem"]
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData);
        }
    }
    if (elist.length > 0) {
        var jsonStr = YAHOO.lang.JSON.stringify(elist);
        var SaveUrl = "../EHR/workTimeAjax.aspx?flag=SaveDatDutyInfo&r=" + Math.random() + "&json=" + jsonStr + "&CategoryID=" + CategoryID;
        YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str == "1") {
                        alert("保存成功");
                        window.parent.$("#tabs").tabs('close', _PageTitle);
                    }
                    else {
                        alert(str + "\n" + "保存失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("保存失败，数据错误：" + error.statusText);
            }
        }, null);
    }
    else {
        alert("没有选择记录！")
        return;
    }
    window.parent.$("#tabs").tabs('close', _PageTitle);
    window.parent.ReLoadData();
}

